#include <stdio.h>
#include "time_recorder.h"

namespace andrew
{
	namespace tools
	{
		namespace common
		{
			
			struct timeval time_recorder::time_begin;
			struct timeval time_recorder::time_end;
			unsigned long time_recorder::time_span;

			void time_recorder::record_begin()
			{
				gettimeofday(&time_recorder::time_begin,NULL);
			}	
			unsigned long time_recorder::record_end()
			{
				gettimeofday(&time_recorder::time_end,NULL);
				time_recorder::time_span =
					(time_recorder::time_end.tv_usec - time_recorder::time_begin.tv_usec)
					+ 1000000*(time_recorder::time_end.tv_sec	- time_recorder::time_begin.tv_sec);
				return time_recorder::time_span;
			}
		}
	}
}

#ifdef _UTEST__
int main()
{
	andrew::tools::common::time_recorder::record_begin();
	int i = 100;
	while(i--);
	unsigned long _tmp_end_time = andrew::tools::common::time_recorder::record_end();
	printf("Time used:%ld\n",_tmp_end_time);
	return 0;
}
#endif
